package com.controller;

import com.pojo.Dictionary;
import com.service.DictionaryService;
import com.util.Pager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/base/dictionary")
public class DictionaryHandler {
    @Resource
    private DictionaryService dictionaryService;

    /**
     * 分页查询
     * @param dictionary
     * @param limit
     * @param offset
     * @return Pager
     */
    @RequestMapping("/searchByDictionaryPager")
    public Pager<Dictionary> searchByDictionaryPager(Dictionary dictionary,Integer limit,Integer offset){
        Pager<Dictionary> pager=new Pager<>();
        pager.setOffSet(offset);
        pager.setLimit(limit);
        pager.setCondition(dictionary);
        return dictionaryService.searchByDictionaryPager(pager);
    }

    /**
     * 修改
     * @param dictionary
     * @return String
     */
    @RequestMapping("/updateDictionary")
    public String updateDictionary(Dictionary dictionary){
        String msg="修改失败！";
        int i = dictionaryService.update(dictionary);
        if(i>0){
            msg="修改成功！";
        }
        return msg;
    }

    /**
     * 添加
     * @param dictionary
     * @return String
     */
    @RequestMapping("/addDictionary")
    public String addDictionary(Dictionary dictionary){
        String msg="添加失败！";
        int i = dictionaryService.add(dictionary);
        if(i>0){
            msg="添加成功！";
        }
        return msg;
    }

}
